<el-card>
  <h1>用户管理</h1>
  <el-divider />
  <el-form inline :model="findUserParam">
    <el-form-item>
      <el-input v-model="findUserParam.name" placeholder="用户名" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="search">
        <template #icon><Search></Search></template>
        搜索
      </el-button>
    </el-form-item>
  </el-form>
</el-card>

<el-card style="margin-top: 20px">
  <template #header>
    <el-button circle plain @click="() => getUsers()">
      <template #icon><Refresh></Refresh></template>
    </el-button>
    <el-button type="primary" @click="addUpdateDialogShow">
      <template #icon><Plus></Plus></template>
      添加用户
    </el-button>
  </template>
  <el-table v-loading="loading" :data="userList" style="width: 100%">
    <el-table-column prop="id" label="ID" width="180" />
    <el-table-column prop="name" label="名称" width="180" />
    <el-table-column prop="password" label="密码" />
    <el-table-column prop="create_time" label="添加时间" :formatter="({create_time}) => timeFormat(create_time)" />
    <el-table-column prop="update_time" label="更新时间" :formatter="({update_time}) => timeFormat(update_time)" />
    <el-table-column label="操作">
      <template #default="{ row }">
        <el-popconfirm title="确认删除当前用户？" @confirm="deleteUser(row.id)">
          <template #reference>
            <el-button text type="danger" size="small">删除</el-button>
          </template>
        </el-popconfirm>
        <el-button text type="primary" size="small" @click="editUser(row)">编辑</el-button>
      </template>
    </el-table-column>
  </el-table>
</el-card>

<el-dialog v-model="addUpdateDialogVisible" :title="userDialogTitle" width="30%">
  <el-form ref="userRef" label-width="100px" :model="userForm" :rules="userFormRules">
    <el-form-item label="名称" prop="name">
      <el-input v-model="userForm.name" />
    </el-form-item>
    <el-form-item label="密码" prop="password">
      <el-input v-model="userForm.password" />
    </el-form-item>
  </el-form>
  <template #footer>
    <span class="dialog-footer">
      <el-button @click="addUpdateDialogVisible = false">取消</el-button>
      <el-button type="primary" @click="addUser">确认</el-button>
    </span>
  </template>
</el-dialog>
